{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import iplantuml"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. 二分查找"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Writing output for /home/jack/Desktop/structures-algorithms/23fce798-65b7-4141-adfa-d691e8d88ab5.uml to 23fce798-65b7-4141-adfa-d691e8d88ab5.svg\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" contentStyleType=\"text/css\" height=\"722px\" preserveAspectRatio=\"none\" style=\"width:431px;height:722px;background:#FFFFFF;\" version=\"1.1\" viewBox=\"0 0 431 722\" width=\"431px\" zoomAndPan=\"magnify\"><defs/><g><ellipse cx=\"218.2429\" cy=\"20\" fill=\"#222222\" rx=\"10\" ry=\"10\" style=\"stroke:#222222;stroke-width:1.0;\"/><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"110.9789\" x=\"162.7534\" y=\"50\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"90.9789\" x=\"172.7534\" y=\"71.1387\">低位=0, 高位=n</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"160.0806\" x=\"138.2026\" y=\"103.9688\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"140.0806\" x=\"148.2026\" y=\"125.1074\">中位 = (低位 + 高位) // 2</text><polygon fill=\"#F1F1F1\" points=\"48,157.9375,148.0093,157.9375,160.0093,169.9375,148.0093,181.9375,48,181.9375,36,169.9375,48,157.9375\" style=\"stroke:#181818;stroke-width:0.5;\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"11\" lengthAdjust=\"spacing\" textLength=\"100.0093\" x=\"48\" y=\"173.7456\">序列[中位] == 标的</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"67.924\" x=\"64.0426\" y=\"201.9375\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"47.924\" x=\"74.0426\" y=\"223.0762\">&lt;= 中位</text><ellipse cx=\"98.0047\" cy=\"280.9063\" fill=\"none\" rx=\"10\" ry=\"10\" style=\"stroke:#222222;stroke-width:1.5;\"/><line style=\"stroke:#222222;stroke-width:2.5;\" x1=\"91.8175\" x2=\"104.1918\" y1=\"274.7191\" y2=\"287.0934\"/><line style=\"stroke:#222222;stroke-width:2.5;\" x1=\"104.1918\" x2=\"91.8175\" y1=\"274.7191\" y2=\"287.0934\"/><polygon fill=\"#F1F1F1\" points=\"192.0093,157.9375,282.8018,157.9375,294.8018,169.9375,282.8018,181.9375,192.0093,181.9375,180.0093,169.9375,192.0093,157.9375\" style=\"stroke:#181818;stroke-width:0.5;\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"11\" lengthAdjust=\"spacing\" textLength=\"90.7925\" x=\"192.0093\" y=\"173.7456\">序列[中位] &lt; 标的</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"111.0023\" x=\"181.9044\" y=\"201.9375\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"91.0023\" x=\"191.9044\" y=\"223.0762\">低位 = 中位 + 1</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"85.684\" x=\"308.2832\" y=\"232.4375\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"65.684\" x=\"318.2832\" y=\"253.5762\">高位 = 中位</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"160.0806\" x=\"138.2026\" y=\"386.6167\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"140.0806\" x=\"148.2026\" y=\"407.7554\">中位 = (低位 + 高位) // 2</text><polygon fill=\"#F1F1F1\" points=\"48,440.5854,148.0093,440.5854,160.0093,452.5854,148.0093,464.5854,48,464.5854,36,452.5854,48,440.5854\" style=\"stroke:#181818;stroke-width:0.5;\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"11\" lengthAdjust=\"spacing\" textLength=\"100.0093\" x=\"48\" y=\"456.3936\">序列[中位] == 标的</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"67.924\" x=\"64.0426\" y=\"484.5854\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"47.924\" x=\"74.0426\" y=\"505.7241\">&lt;= 中位</text><ellipse cx=\"98.0047\" cy=\"563.5542\" fill=\"none\" rx=\"10\" ry=\"10\" style=\"stroke:#222222;stroke-width:1.5;\"/><line style=\"stroke:#222222;stroke-width:2.5;\" x1=\"91.8175\" x2=\"104.1918\" y1=\"557.367\" y2=\"569.7414\"/><line style=\"stroke:#222222;stroke-width:2.5;\" x1=\"104.1918\" x2=\"91.8175\" y1=\"557.367\" y2=\"569.7414\"/><polygon fill=\"#F1F1F1\" points=\"192.0093,440.5854,282.8018,440.5854,294.8018,452.5854,282.8018,464.5854,192.0093,464.5854,180.0093,452.5854,192.0093,440.5854\" style=\"stroke:#181818;stroke-width:0.5;\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"11\" lengthAdjust=\"spacing\" textLength=\"90.7925\" x=\"192.0093\" y=\"456.3936\">序列[中位] &lt; 标的</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"111.0023\" x=\"181.9044\" y=\"484.5854\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"91.0023\" x=\"191.9044\" y=\"505.7241\">低位 = 中位 + 1</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"85.684\" x=\"308.2832\" y=\"515.0854\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"65.684\" x=\"318.2832\" y=\"536.2241\">高位 = 中位</text><polygon fill=\"#F1F1F1\" points=\"188.1381,330.9063,248.3477,330.9063,260.3477,342.9063,248.3477,354.9063,188.1381,354.9063,176.1381,342.9063,188.1381,330.9063\" style=\"stroke:#181818;stroke-width:0.5;\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"11\" lengthAdjust=\"spacing\" textLength=\"24.981\" x=\"222.2429\" y=\"365.1167\">True</text><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"11\" lengthAdjust=\"spacing\" textLength=\"60.2097\" x=\"188.1381\" y=\"346.7144\">低位 &lt; 高位</text><rect fill=\"#F1F1F1\" height=\"33.9688\" rx=\"12.5\" ry=\"12.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"104.0006\" x=\"166.2426\" y=\"635.5542\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"12\" lengthAdjust=\"spacing\" textLength=\"84.0006\" x=\"176.2426\" y=\"656.6929\">抛出未找到异常</text><ellipse cx=\"218.2429\" cy=\"700.5229\" fill=\"none\" rx=\"11\" ry=\"11\" style=\"stroke:#222222;stroke-width:1.0;\"/><ellipse cx=\"218.2429\" cy=\"700.5229\" fill=\"#222222\" rx=\"6\" ry=\"6\" style=\"stroke:#222222;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"30\" y2=\"50\"/><polygon fill=\"#181818\" points=\"214.2429,40,218.2429,50,222.2429,40,218.2429,44\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"83.9688\" y2=\"103.9688\"/><polygon fill=\"#181818\" points=\"214.2429,93.9688,218.2429,103.9688,222.2429,93.9688,218.2429,97.9688\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"98.0047\" x2=\"98.0047\" y1=\"235.9063\" y2=\"270.9063\"/><polygon fill=\"#181818\" points=\"94.0047,260.9063,98.0047,270.9063,102.0047,260.9063,98.0047,264.9063\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"98.0047\" x2=\"98.0047\" y1=\"181.9375\" y2=\"201.9375\"/><polygon fill=\"#181818\" points=\"94.0047,191.9375,98.0047,201.9375,102.0047,191.9375,98.0047,195.9375\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"237.4056\" x2=\"237.4056\" y1=\"181.9375\" y2=\"201.9375\"/><polygon fill=\"#181818\" points=\"233.4056,191.9375,237.4056,201.9375,241.4056,191.9375,237.4056,195.9375\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"237.4056\" x2=\"237.4056\" y1=\"235.9063\" y2=\"310.9063\"/><polygon fill=\"#181818\" points=\"233.4056,300.9063,237.4056,310.9063,241.4056,300.9063,237.4056,304.9063\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"160.0093\" x2=\"180.0093\" y1=\"169.9375\" y2=\"169.9375\"/><polygon fill=\"#181818\" points=\"170.0093,165.9375,180.0093,169.9375,170.0093,173.9375,174.0093,169.9375\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"137.9375\" y2=\"142.9375\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"98.0047\" y1=\"142.9375\" y2=\"142.9375\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"98.0047\" x2=\"98.0047\" y1=\"142.9375\" y2=\"157.9375\"/><polygon fill=\"#181818\" points=\"94.0047,147.9375,98.0047,157.9375,102.0047,147.9375,98.0047,151.9375\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"294.8018\" x2=\"351.1252\" y1=\"169.9375\" y2=\"169.9375\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"351.1252\" x2=\"351.1252\" y1=\"169.9375\" y2=\"232.4375\"/><polygon fill=\"#181818\" points=\"347.1252,222.4375,351.1252,232.4375,355.1252,222.4375,351.1252,226.4375\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"351.1252\" x2=\"351.1252\" y1=\"266.4063\" y2=\"310.9063\"/><polygon fill=\"#181818\" points=\"347.1252,300.9063,351.1252,310.9063,355.1252,300.9063,351.1252,304.9063\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"351.1252\" y1=\"310.9063\" y2=\"310.9063\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"98.0047\" x2=\"98.0047\" y1=\"518.5542\" y2=\"553.5542\"/><polygon fill=\"#181818\" points=\"94.0047,543.5542,98.0047,553.5542,102.0047,543.5542,98.0047,547.5542\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"98.0047\" x2=\"98.0047\" y1=\"464.5854\" y2=\"484.5854\"/><polygon fill=\"#181818\" points=\"94.0047,474.5854,98.0047,484.5854,102.0047,474.5854,98.0047,478.5854\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"237.4056\" x2=\"237.4056\" y1=\"464.5854\" y2=\"484.5854\"/><polygon fill=\"#181818\" points=\"233.4056,474.5854,237.4056,484.5854,241.4056,474.5854,237.4056,478.5854\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"237.4056\" x2=\"237.4056\" y1=\"518.5542\" y2=\"593.5542\"/><polygon fill=\"#181818\" points=\"233.4056,583.5542,237.4056,593.5542,241.4056,583.5542,237.4056,587.5542\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"160.0093\" x2=\"180.0093\" y1=\"452.5854\" y2=\"452.5854\"/><polygon fill=\"#181818\" points=\"170.0093,448.5854,180.0093,452.5854,170.0093,456.5854,174.0093,452.5854\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"420.5854\" y2=\"425.5854\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"98.0047\" y1=\"425.5854\" y2=\"425.5854\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"98.0047\" x2=\"98.0047\" y1=\"425.5854\" y2=\"440.5854\"/><polygon fill=\"#181818\" points=\"94.0047,430.5854,98.0047,440.5854,102.0047,430.5854,98.0047,434.5854\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"294.8018\" x2=\"351.1252\" y1=\"452.5854\" y2=\"452.5854\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"351.1252\" x2=\"351.1252\" y1=\"452.5854\" y2=\"515.0854\"/><polygon fill=\"#181818\" points=\"347.1252,505.0854,351.1252,515.0854,355.1252,505.0854,351.1252,509.0854\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"351.1252\" x2=\"351.1252\" y1=\"549.0542\" y2=\"593.5542\"/><polygon fill=\"#181818\" points=\"347.1252,583.5542,351.1252,593.5542,355.1252,583.5542,351.1252,587.5542\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"351.1252\" y1=\"593.5542\" y2=\"593.5542\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"354.9063\" y2=\"386.6167\"/><polygon fill=\"#181818\" points=\"214.2429,376.6167,218.2429,386.6167,222.2429,376.6167,218.2429,380.6167\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"593.5542\" y2=\"603.5542\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"405.9672\" y1=\"603.5542\" y2=\"603.5542\"/><polygon fill=\"#181818\" points=\"401.9672,489.1831,405.9672,479.1831,409.9672,489.1831,405.9672,485.1831\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"405.9672\" x2=\"405.9672\" y1=\"342.9063\" y2=\"603.5542\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"405.9672\" x2=\"260.3477\" y1=\"342.9063\" y2=\"342.9063\"/><polygon fill=\"#181818\" points=\"270.3477,338.9063,260.3477,342.9063,270.3477,346.9063,266.3477,342.9063\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"176.1381\" x2=\"24\" y1=\"342.9063\" y2=\"342.9063\"/><polygon fill=\"#181818\" points=\"20,475.1831,24,485.1831,28,475.1831,24,479.1831\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"24\" x2=\"24\" y1=\"342.9063\" y2=\"615.5542\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"24\" x2=\"218.2429\" y1=\"615.5542\" y2=\"615.5542\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"615.5542\" y2=\"635.5542\"/><polygon fill=\"#181818\" points=\"214.2429,625.5542,218.2429,635.5542,222.2429,625.5542,218.2429,629.5542\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"310.9063\" y2=\"330.9063\"/><polygon fill=\"#181818\" points=\"214.2429,320.9063,218.2429,330.9063,222.2429,320.9063,218.2429,324.9063\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"218.2429\" x2=\"218.2429\" y1=\"669.5229\" y2=\"689.5229\"/><polygon fill=\"#181818\" points=\"214.2429,679.5229,218.2429,689.5229,222.2429,679.5229,218.2429,683.5229\" style=\"stroke:#181818;stroke-width:1.0;\"/><!--SRC=[Aov9B2fHuB9wihVloTvUMmCTXPUhPu1OUTP0mHrhWKm5MmKDYBI2DbHMKq5VNy78cYipJUFfhlwd7TEZ8KfZ5Mnj5PujQ7y-gqMJIm48h6ni5I1Irc1-QbuALsfESIgcHXjKVL0BORg1DXjQWtL2f27EK40O3ZGuCushF2Cp9nNcM1kOOpEBDKAAIbDX9XFo54WLGOzXynpCWs2Q24_YzYZC18Go30z3BGDw6aY2_SrbzQnhzjFsNS_ch7hMkUzfnuQdUvgUxjXXpLLSaby00000]--></g></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%plantuml\n",
    "@startuml\n",
    "start \n",
    ":低位=0, 高位=n;\n",
    ":中位 = (低位 + 高位) // 2;\n",
    "if(序列[中位] == 标的)\n",
    "    :<= 中位;\n",
    "    end\n",
    "elseif(序列[中位] < 标的)\n",
    "    :低位 = 中位 + 1;\n",
    "else\n",
    "    :高位 = 中位;\n",
    "endif\n",
    "while(低位 < 高位)is(True)\n",
    "    :中位 = (低位 + 高位) // 2;\n",
    "    if(序列[中位] == 标的)\n",
    "        :<= 中位;\n",
    "        end\n",
    "    elseif(序列[中位] < 标的)\n",
    "        :低位 = 中位 + 1;\n",
    "    else\n",
    "        :高位 = 中位;\n",
    "    endif\n",
    "endwhile\n",
    ":抛出未找到异常;\n",
    "stop\n",
    "@enduml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "def 二分查找(序列: list[int], 标的: int) -> int:\n",
    "    低位 = 0\n",
    "    高位 = len(序列)\n",
    "    中位 = (低位 + 高位) // 2\n",
    "    if 序列[中位] == 标的:\n",
    "        return 中位\n",
    "    elif 序列[中位] < 标的:\n",
    "        低位 = 中位 + 1\n",
    "    else:\n",
    "        高位 = 中位\n",
    "    \n",
    "    while(低位 < 高位):\n",
    "        中位 = (低位 + 高位) // 2\n",
    "        if 序列[中位] == 标的:\n",
    "            return 中位\n",
    "        elif 序列[中位] < 标的:\n",
    "            低位 = 中位 + 1\n",
    "        else:\n",
    "            高位 = 中位\n",
    "    raise ValueError(f'序列 {序列} 中未找到标的 {标的}')\n",
    "\n",
    "序列 = [-3, 4, 7, 9, 13, 45, 67, 89, 100, 180]\n",
    "print(二分查找(序列, 9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "序列 [-3, 4, 7, 9, 13, 45, 67, 89, 100, 180] 中未找到标的 -1\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    二分查找(序列, -1)\n",
    "except ValueError as e:\n",
    "    print(e)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
